
abstract class AbstractRoute{
    //抽象类AbstractRoute,3个抽象方法getFare(),getDistance(),queryStations()
    public abstract double getFare();
    public abstract double getDistance();
   public abstract void queryStations();
}
class SpecificRoute extends AbstractRoute{
    //子类SpecificRoute继承父类AbstractRoute
    private String name;
    private String[] stations;
    private String startStation;
    private String endStation;

    public SpecificRoute() {
    }
    public SpecificRoute(String name, String[] stations, String startStation, String endStation) {
        this.name = name;
        this.stations = stations;
        this.startStation = startStation;
        this.endStation = endStation;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String[] getStations() {
        return stations;
    }

    public void setStations(String[] stations) {
        this.stations = stations;
    }

    public String getStartStation() {
        return startStation;
    }

    public void setStartStation(String startStation) {
        this.startStation = startStation;
    }

    public String getEndStation() {
        return endStation;
    }

    public void setEndStation(String endStation) {
        this.endStation = endStation;
    }
    //重写父类的抽象方法
    @Override
    public double getFare() {
        return this.stations.length*1;
    }
    @Override
    public double getDistance() {
        return this.stations.length*2;
    }
    @Override
    public void queryStations() {
        System.out.println(getName()+"的站点有：");
        for (String station: stations) {
            System.out.print(station+" ");
        }
        System.out.println();
    }
}
public class Test{
    public static void main(String[] args) {
        AbstractRoute abstractRoute=new SpecificRoute("101",new String[]{"S1","S2","S3","S4","S5"},
                "S1","S5");
        abstractRoute.queryStations();
        System.out.println("路程为："+ abstractRoute.getDistance()+"公里"+"  "+"费用为"+abstractRoute.getFare()+"元");
    }
}


